package com.dkm.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dkm.entity.Counselor;
import com.dkm.service.CounselorService;
import com.dkm.util.LayuiJsonUilt;
import com.dkm.util.ResultUtil;

@RestController
@RequestMapping("/counselor")
public class CounselorController {

	//注入咨询师业务层
	@Autowired
	private CounselorService counselorService;
	
	@GetMapping
	@RequiresPermissions(value = "counselor:query")
	public LayuiJsonUilt<Counselor> findAllCounselors(LayuiJsonUilt<Counselor> lj,Counselor counselor) {
//		List<Order> orders=new ArrayList<Sort.Order>();
//		orders.add(new Order(Direction.DESC, "weight"));
//		Sort sort=Sort.by(orders);
		//创建分页对象
		Pageable pageable=PageRequest.of(lj.getPage(), lj.getLimit(),Sort.by(Direction.DESC, "weight"));
		
		Page<Counselor> page=counselorService.findAllCounselors(counselor, pageable);
		//设置数据和数据长度
		lj.setData(page.getContent());
		lj.setCount(page.getTotalElements());
		return lj;
	}
	
	//修改咨询师权重值
	@PutMapping
	@RequiresPermissions(value = "counselor:updateWeigth")
	public ResultUtil updateCounselorWeight(Counselor counselor) {
		
		return counselorService.updateCounselorWeight(counselor);
	}
	//获取自动分配状态(待修改判断咨询经理)
	@GetMapping("/getAutoAllocationStatus")
	public ResultUtil getAutoAllocationStatus(String user_id) {
		
		return counselorService.getAutoAllocationStatus(user_id);
	}
	
	//开启/关闭自动分配
	@GetMapping("/autoAllocation")
	public ResultUtil autoAllocation(String user_id) {
		
		
		return counselorService.autoAllocation(user_id);
	}
}
